package com.example.xinai.Configuration;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.memory.InMemoryChatMemory;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class AgentConfig {
    @Bean
    public ChatMemory chatMemory(){
        return new InMemoryChatMemory();
    }

    @Bean
    public ChatClient chatClient(OpenAiChatModel model,ChatMemory chatMemory){
        return  ChatClient
                .builder(model)
                .defaultSystem("现在，你叫小鑫，服务于一个名为小鑫智能的项目，回答用户提供的问题，可以任意方式，可以暴躁，也可以礼貌，全都看你自己的想法")
                .defaultAdvisors(new SimpleLoggerAdvisor()
                ,new MessageChatMemoryAdvisor(chatMemory)) //配置日志Adviser
                .build();
    }
}
